package com.droidcar;

import java.text.NumberFormat;
import java.util.ArrayList;

import act.droidcar.R;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Adaptador de listagem dos veiculos retornados a partir de um ArrayList de VeiculosBD
 */
public class AdapterListView extends BaseAdapter {

	 
    private LayoutInflater mInflater;
    private ArrayList<VeiculosBD> itens;
    private NumberFormat nmf = NumberFormat.getCurrencyInstance();
 
    public AdapterListView(Context context, ArrayList<VeiculosBD> itens) {
        //Itens que preencheram o listview
        this.itens = itens;
        //responsavel por pegar o Layout do item.
        mInflater = LayoutInflater.from(context);
    }
 
    /**
     * Retorna a quantidade de itens
     */
    public int getCount() {
        return itens.size();
    }
 
    /**
     * Retorna o item de acordo com a posicao dele na tela.
     */
    public VeiculosBD getItem(int position) {
        return itens.get(position);
    }
 

    public long getItemId(int position) {
        return position;
    }
 
    public View getView(int position, View view, ViewGroup parent) {
    	VeiculosBD item = itens.get(position);
        view = mInflater.inflate(R.layout.item_listview, null);
 
        ((TextView) view.findViewById(R.id.text)).setText(       		
        		item.getMDO_DESCRICAO() + " - " + item.getVCL_ANO() + " - " + nmf.format(item.getVCL_VALOR())         		
        		);
        Drawable drawable = item.LoadImageFromWebOperations(item.getVCL_IMG_MINI());
        ( (ImageView) view.findViewById(R.id.imagemview) ).setImageDrawable(drawable);
 
        return view;
    }

}
